// var i;
// var $uI_GameOver_UIBindings = require("./UI_GameOver_UIBindings");
// var $uIView = require("./UIView");
// var $gameDataManager = require("./GameDataManager");
// var $gameGlobalVariable = require("./GameGlobalVariable");
// var $excel = require("./Excel");
// var $hallGlobalVariable = require("./HallGlobalVariable");
// var $const_Hall = require("./Const_Hall");
// var $uI_GameOverItem = require("./UI_GameOverItem");
// var $logManager = require("./LogManager");
// var $playerDataManager = require("./PlayerDataManager");
// var $const_Common = require("./Const_Common");
// var $const_Game = require("./Const_Game");
// var $eventManager = require("./EventManager");
// var $evenType = require("./EvenType");
// var $audioManager = require("./AudioManager");
// var $bundleConfig = require("./BundleConfig");
// var $aIControl = require("./AIControl");
// var $commonUtils = require("./CommonUtils");
// var $tTAPI = require("./TTAPI");
// var C = cc._decorator;
// var B = C.ccclass;
// var k = C.property;
// var P = C.inspector;
// var G = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         t.nowdata = {};
//         t.nowlevel = 1;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype._show = function (e) {
//         var t = [];
//         for (var o = 1; o < arguments.length; o++) {
//             t[o - 1] = arguments[o];
//         }
//         this.nowdata = e;
//         this.nowlevel = $gameGlobalVariable.GameGlobalVariable.nowlevel;
//         this.auto_ui.btn_fenxiang.node.active = !0;
//         if (1 == $gameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
//             this.auto_ui.btn_fenxiang.node.active = !1;
//             this.nowlevel = $gameGlobalVariable.GameGlobalVariable.teshulevel;
//             $playerDataManager.PlayerDataMgr.subWuJinCount(1);
//         }
//         if (1 == this.nowdata.type) {
//             this.auto_ui.node_successtop.active = !1;
//             this.auto_ui.node_failtop.active = !0;
//             this.scaleNode(this.auto_ui.node_failtop);
//             var n = $gameDataManager.GameDataMgr.getNowLevelBoshuState(
//                 this.nowlevel,
//                 $gameGlobalVariable.GameGlobalVariable.isTeShuLevel()
//             );
//             this.auto_ui.txt_nowboshu.string = "最高进度:第" + n + "波";
//             $audioManager.AudioMgr.playEffect("sound/失败", !1, $bundleConfig.BundleNames.Game);
//         } else {
//             $audioManager.AudioMgr.playEffect("sound/胜利", !1, $bundleConfig.BundleNames.Game);
//             this.auto_ui.node_successtop.active = !0;
//             this.scaleNode(this.auto_ui.node_successtop);
//             this.auto_ui.node_failtop.active = !1;
//         }
//         if (1 == $gameGlobalVariable.GameGlobalVariable.isTeShuLevel()) {
//             this.initTiaoZhanAward();
//         } else {
//             this.initAward();
//         }
//         this.AICheck();
//         $gameDataManager.GameDataMgr.updateCiTiao(this.nowlevel, null);
//         $commonUtils.default.cleanGold();
//     };
//     t.prototype.scaleNode = function (e) {
//         this.scheduleOnce(function () {
//             e.scale = 0;
//             cc.tween(e)
//                 .to(
//                     0.3,
//                     {
//                         scale: 1
//                     },
//                     {
//                         easing: "backOut"
//                     }
//                 )
//                 .start();
//         });
//     };
//     t.prototype.initTiaoZhanAward = function () {
//         var e = 100 * $gameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
//         this.itemData = new $const_Hall.GetItemsData();
//         this.itemData.ids = [];
//         this.itemData.counts = [];
//         this.itemData.ids.push(12345);
//         this.itemData.counts.push(e);
//         this.initAwardUi(this.itemData);
//     };
//     t.prototype.initAward = function () {
//         var e = this;
//         var t = $excel.Excel.shuiguoguanqia(this.nowlevel);
//         var o = t.levelaward;
//         var n = $gameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 2);
//         var i = o[0][1];
//         this.itemData = new $const_Hall.GetItemsData();
//         this.itemData.ids = [];
//         this.itemData.counts = [];
//         $gameGlobalVariable.GameGlobalVariable.isFirstGuide = !1;
//         if (
//             $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.仓库升级) ==
//             $const_Common.UpEquipLevelGuideIndex.给固定奖励1
//         ) {
//             this.itemData.ids.push($hallGlobalVariable.default.goldId);
//             this.itemData.counts.push(200);
//             this.itemData.ids.push($const_Game.FruitId.杨桃忍者);
//             this.itemData.counts.push(4);
//         } else {
//             {
//                 var a = Math.floor(n * (i / t.levelboshuid.length));
//                 if (a > 0) {
//                     this.itemData.ids.push($hallGlobalVariable.default.goldId);
//                     this.itemData.counts.push(a);
//                 }
//                 $gameGlobalVariable.GameGlobalVariable.addjinbi = a;
//                 var r = function (e, o) {
//                     if (n < e) {
//                         return 0;
//                     } else {
//                         return Math.floor(((n + 1 - e) / (t.levelboshuid.length + 1 - e)) * o);
//                     }
//                 };
//                 var c = o[1];
//                 var s = r(t.awardboshuid[0], c[2]);
//                 $logManager.LogMgr.debug("绿色碎片数量", s);
//                 var f = o[2];
//                 var v = 0;
//                 if (f) {
//                     v = r(t.awardboshuid[1], f[2]);
//                     $logManager.LogMgr.debug("蓝色碎片数量", v);
//                 }
//                 var b = o[3];
//                 var w = 0;
//                 if (b) {
//                     w = r(t.awardboshuid[2], b[2]);
//                     $logManager.LogMgr.debug("紫碎片数量", w);
//                 }
//                 $hallGlobalVariable.default.GetSuiPian([s, v, w]).forEach(function (t, o) {
//                     e.itemData.ids.push(o);
//                     e.itemData.counts.push(t);
//                     $playerDataManager.PlayerDataMgr.AddEquipFragments(o, t);
//                 });
//             }
//         }
//         this.initAwardUi(this.itemData);
//         var I = $gameDataManager.GameDataMgr.getNowMaxLevel();
//         if (cc.sys.platform == cc.sys.BYTEDANCE_GAME) {
//             $tTAPI.default.setImRankData(I);
//         }
//     };
//     t.prototype.getNodes = function (e) {
//         var t = e.ids.length;
//         var o = 1;
//         if (t > 4) {
//             var n = t % 4;
//             o = (t - n) / 4;
//             if (n > 0) {
//                 o += 1;
//             }
//         }
//         var i = this.auto_ui.scroll_nowscroll.content.children;
//         var a = [];
//         var r = 0;
//         for (var c = 0; c < i.length; c++) {
//             var s = i[c];
//             if (c < o) {
//                 s.active = !0;
//                 s.children[0].children.forEach(function (t) {
//                     if (r < e.ids.length) {
//                         t.scale = 0;
//                         a.push(t);
//                         r++;
//                     } else {
//                         t.active = !1;
//                     }
//                 });
//             } else {
//                 s.active = !1;
//             }
//         }
//         return a;
//     };
//     t.prototype.initAwardUi = function (e) {
//         var t = this.getNodes(e);
//         var o = 0;
//         this.schedule(
//             function () {
//                 var n = t[o];
//                 var i = e.ids[o];
//                 var a = e.counts[o];
//                 n.getComponent($uI_GameOverItem.default).initUi(i, a);
//                 cc.tween(n)
//                     .to(
//                         0.3,
//                         {
//                             scale: 1
//                         },
//                         {
//                             easing: "backOut"
//                         }
//                     )
//                     .start();
//                 o += 1;
//             },
//             0.1,
//             t.length - 1
//         );
//     };
//     t.prototype._clickListener = function (e) {
//         var t = this;
//         var o = this.auto_ui;
//         switch (e) {
//             case o.btn_fenxiang:
//                 if (cc.sys.isBrowser) {
//                     var n = this.itemData.counts;
//                     for (var i = 0; i < n.length; i++) {
//                         var a = this.itemData.counts[i];
//                         this.itemData.counts[i] = 2 * a;
//                     }
//                     this.initAwardUi(this.itemData);
//                     this.auto_ui.btn_fenxiang.node.active = !1;
//                 } else {
//                     $commonUtils.default.onshare(function (e) {
//                         if (e) {
//                             var o = t.itemData.counts;
//                             for (var n = 0; n < o.length; n++) {
//                                 var i = t.itemData.counts[n];
//                                 t.itemData.counts[n] = 2 * i;
//                             }
//                             t.initAwardUi(t.itemData);
//                             t.auto_ui.btn_fenxiang.node.active = !1;
//                         }
//                     });
//                 }
//                 break;
//             case o.btn_queding:
//                 this.GetReward(!1);
//                 this.onBackHome();
//         }
//     };
//     t.prototype.GetReward = function (e) {
//         if (this.itemData) {
//             for (var t = 0; t < this.itemData.ids.length; t++) {
//                 var o = this.itemData.ids[t];
//                 var n = this.itemData.counts[t];
//                 if (e) {
//                     n *= 2;
//                 }
//                 switch (o) {
//                     case $hallGlobalVariable.default.goldId:
//                         $playerDataManager.PlayerDataMgr.AddGold(n);
//                         break;
//                     case 12345:
//                         var i = $gameDataManager.GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
//                         $gameDataManager.GameDataMgr.updateTiaoZhanFen(1, 100 * i);
//                         break;
//                     default:
//                         $playerDataManager.PlayerDataMgr.AddEquipFragments(o, n);
//                 }
//             }
//             if (
//                 $playerDataManager.PlayerDataMgr.GetGuideIndexByTaskName($const_Common.GuideName.仓库升级) ==
//                 $const_Common.UpEquipLevelGuideIndex.给固定奖励1
//             ) {
//                 $playerDataManager.PlayerDataMgr.SetGuideIndex(
//                     $const_Common.GuideName.仓库升级,
//                     $const_Common.UpEquipLevelGuideIndex.引导点击仓库水果2
//                 );
//             }
//         }
//     };
//     t.prototype.onBackHome = function () {
//         this.nowdata.back(2);
//         this.onCloseView();
//     };
//     t.prototype.onBack = function () {
//         this.nowdata.back(2);
//         this.onCloseView();
//     };
//     t.prototype.onCloseView = function () {
//         this._close();
//         $eventManager.EventMgr.dispatchEvent($evenType.EVENT_TYPE.Game_Value_Fei);
//     };
//     t.prototype.AICheck = function () {
//         var e = this;
//         if ($aIControl.default._instance.isOpen) {
//             this.scheduleOnce(function () {
//                 $aIControl.default._instance.ShowClickBtn(e.auto_ui.btn_queding.node, function () {
//                     e.GetReward(!1);
//                     e.onBackHome();
//                 });
//             }, 1);
//         }
//     };
//     __decorate([k($uI_GameOver_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([B], t);
// })($uIView.default);
// exports.default = G;

// import UI_GameOver_UIBindings from "./UI_GameOver_UIBindings";
// import UIView from "./UIView";
// import {GameDataMgr} from "./GameDataManager";
// import {GameGlobalVariable} from "./GameGlobalVariable";
// import {Excel} from "./Excel";
// import HallGlobalVariable from "./HallGlobalVariable";
// import UI_GameOverItem from "./UI_GameOverItem";
// import {LogMgr} from "./LogManager";
// import {EventMgrInstance} from "./EventManager";
// import {EVENT_TYPE} from "./EvenType";
// import {AudioMgr} from "./AudioManager";
// import {BundleNames} from "./BundleConfig";
// import AIControl from "./AIControl";
// import CommonUtils from "./CommonUtils";
// import { PlayerDataMgr } from './PlayerDataManager';
// import { GetItemsData } from "./Const_Hall";
// // import TTAPI from "./TTAPI";
// import { GuideName, UpEquipLevelGuideIndex } from "./Const_Common";
// import { FruitId } from "./Const_Game";

// const { ccclass, property } = cc._decorator;

// /** 
//  * 游戏结束界面控制类
//  * 建议类名：GameOverView
//  */
// @ccclass
// export default class UI_GameOver extends UIView {
//     @property(UI_GameOver_UIBindings)
//     public auto_ui: UI_GameOver_UIBindings = null;

//     public nowdata: any = {};
//     public nowlevel: number = 1;

//     public itemData: GetItemsData = null;

//     /**
//      * 显示游戏结束界面
//      * @param {any} e 游戏结束的数据
//      * 建议方法名：showGameOver
//      */
//     public _show(...args: any[]): void {
//         const [e] = args;
//         this.nowdata = e;
//         this.nowlevel = GameGlobalVariable.nowlevel;
//         this.auto_ui.btn_fenxiang.node.active = true;

//         if (GameGlobalVariable.isTeShuLevel() === 1) {
//             this.auto_ui.btn_fenxiang.node.active = false;
//             this.nowlevel = GameGlobalVariable.teshulevel;
//             PlayerDataMgr.subWuJinCount(1);
//         }
//         if (this.nowdata.type === 1) {
//             this.updateFailUI();
//         } else {
//             this.updateSuccessUI();
//         }

//         if (GameGlobalVariable.isTeShuLevel() === 1) {
//             this.initTiaoZhanAward();
//         } else {
//             this.initAward();
//         }

//         this.AICheck();
//         GameDataMgr.updateCiTiao(this.nowlevel, null);
//         CommonUtils.cleanGold();
//     }

//     private updateFailUI(): void {
//         this.auto_ui.node_successtop.active = false;
//         this.auto_ui.node_failtop.active = true;
//         this.scaleNode(this.auto_ui.node_failtop);
//         const highestBoshuState = GameDataMgr.getNowLevelBoshuState(this.nowlevel, GameGlobalVariable.isTeShuLevel());
//         this.auto_ui.txt_nowboshu.string = `最高进度:第${highestBoshuState}波`;
//         AudioMgr.playEffect("sound/失败", false, BundleNames.Game);
//     }

//     private updateSuccessUI(): void {
//         AudioMgr.playEffect("sound/胜利", false, BundleNames.Game);
//         this.auto_ui.node_successtop.active = true;
//         this.scaleNode(this.auto_ui.node_successtop);
//         this.auto_ui.node_failtop.active = false;
//     }

//     /**
//      * 缩放节点动画
//      * @param node 要进行动画的节点
//      * 建议方法名：animateScaleNode
//      */
//     private scaleNode(node: cc.Node): void {
//         this.scheduleOnce(() => {
//             node.scale = 0;
//             cc.tween(node)
//                 .to(0.3, { scale: 1 }, { easing: "backOut" })
//                 .start();
//         });
//     }

//     /**
//      * 初始化挑战奖励
//      * 建议方法名：initChallengeAward
//      */
//     private initTiaoZhanAward(): void {
//         const multiplier = 100 * GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
//         this.itemData = new GetItemsData();
//         this.itemData.ids = [];
//         this.itemData.counts = [];
//         this.itemData.ids.push(12345);
//         this.itemData.counts.push(multiplier);
//         this.initAwardUi(this.itemData);
//     }

//     /**
//      * 初始化奖励
//      * 建议方法名：initLevelAward
//      */
//     private initAward(): void {
//         const levelConfig = Excel.shuiguoguanqia(this.nowlevel);
//         const levelAwards = levelConfig.levelaward;
//         const boshuState = GameDataMgr.getNowLevelBoshuState(this.nowlevel, 2);
//         const firstAward = levelAwards[0][1];

//         this.itemData = new GetItemsData();
//         this.itemData.ids = [];
//         this.itemData.counts = [];

//         GameGlobalVariable.isFirstGuide = false;

//         if (PlayerDataMgr.GetGuideIndexByTaskName(GuideName.仓库升级) === UpEquipLevelGuideIndex.给固定奖励1) {
//             this.itemData.ids.push(HallGlobalVariable.goldId);
//             this.itemData.counts.push(200);
//             this.itemData.ids.push(FruitId.杨桃忍者);
//             this.itemData.counts.push(4);
//         } else {
//             const calcAward = Math.floor(boshuState * (firstAward / levelConfig.levelboshuid.length));
//             if (calcAward > 0) {
//                 this.itemData.ids.push(HallGlobalVariable.goldId);
//                 this.itemData.counts.push(calcAward);
//             }
//             GameGlobalVariable.addjinbi = calcAward;

//             const r = (e, o) => boshuState < e ? 0 : Math.floor(((boshuState + 1 - e) / (levelConfig.levelboshuid.length + 1 - e)) * o);

//             const greenPiece = r(levelConfig.awardboshuid[0], levelAwards[1][2]);
//             LogMgr.debug("绿色碎片数量", greenPiece);

//             const bluePiece = levelAwards[2] && r(levelConfig.awardboshuid[1], levelAwards[2][2]);
//             LogMgr.debug("蓝色碎片数量", bluePiece);

//             const purplePiece = levelAwards[3] && r(levelConfig.awardboshuid[2], levelAwards[3][2]);
//             LogMgr.debug("紫碎片数量", purplePiece);

//             HallGlobalVariable.GetSuiPian([greenPiece, bluePiece, purplePiece]).forEach((count, idx) => {
//                 this.itemData.ids.push(idx);
//                 this.itemData.counts.push(count);
//                 PlayerDataMgr.AddEquipFragments(idx, count);
//             });
//         }
//         this.initAwardUi(this.itemData);
//         const maxLevel = GameDataMgr.getNowMaxLevel();
//         if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
//             // TTAPI.setImRankData(maxLevel);
//         }
//     }

//     /**
//      * 获取当前的节点列表
//      * @param {any} awardData 奖励数据
//      * @returns {cc.Node[]} 当前的节点列表
//      * 建议方法名：getCurrentNodes
//      */
//     private getNodes(awardData): cc.Node[] {
//         const itemCount = awardData.ids.length;
//         let rowCount = 1;
//         if (itemCount > 4) {
//             const remainder = itemCount % 4;
//             rowCount = (itemCount - remainder) / 4 + (remainder > 0 ? 1 : 0);
//         }
//         const children = this.auto_ui.scroll_nowscroll.content.children;
//         const nodeArray = [];
//         let itemIndex = 0;

//         for (let i = 0; i < children.length; i++) {
//             const row = children[i];
//             if (i < rowCount) {
//                 row.active = true;
//                 row.children[0].children.forEach((child) => {
//                     if (itemIndex < awardData.ids.length) {
//                         child.scale = 0;
//                         nodeArray.push(child);
//                         itemIndex++;
//                     } else {
//                         child.active = false;
//                     }
//                 });
//             } else {
//                 row.active = false;
//             }
//         }
//         return nodeArray;
//     }

//     /**
//      * 初始化奖励UI
//      * @param {any} awardData 奖励数据
//      * 建议方法名：initAwardUserInterface
//      */
//     private initAwardUi(awardData): void {
//         const nodes = this.getNodes(awardData);
//         let currentIndex = 0;
//         this.schedule(
//             () => {
//                 const currentNode = nodes[currentIndex];
//                 const itemId = awardData.ids[currentIndex];
//                 const itemCount = awardData.counts[currentIndex];
//                 currentNode.getComponent(UI_GameOverItem).initUi(itemId, itemCount);
//                 cc.tween(currentNode)
//                     .to(0.3, { scale: 1 }, { easing: "backOut" })
//                     .start();
//                 currentIndex += 1;
//             },
//             0.1,
//             nodes.length - 1
//         );
//     }

//     /**
//      * 点击事件监听器
//      * @param {cc.Event.EventCustom} event 点击事件
//      * 建议方法名：clickListener
//      */
//     protected _clickListener(event: cc.Button): void {
//         const uiBindings = this.auto_ui;
//         switch (event) {
//             case uiBindings.btn_fenxiang:
//                 this.handleShareButtonClick();
//                 break;
//             case uiBindings.btn_queding:
//                 this.GetReward(false);
//                 this.onBackHome();
//         }
//     }

//     private handleShareButtonClick(): void {
//         if (cc.sys.isBrowser) {
//             this.doubleRewards();
//             this.auto_ui.btn_fenxiang.node.active = false;
//         } else {
//             CommonUtils.onShare((isShared) => {
//                 if (isShared) {
//                     this.doubleRewards();
//                     this.auto_ui.btn_fenxiang.node.active = false;
//                 }
//             });
//         }
//     }

//     private doubleRewards(): void {
//         this.itemData.counts = this.itemData.counts.map(count => count * 2);
//         this.initAwardUi(this.itemData);
//     }

//     /**
//      * 获取奖励
//      * @param {boolean} isDouble 是否双倍
//      * 建议方法名：getReward
//      */
//     private GetReward(isDouble: boolean): void {
//         if (this.itemData) {
//             this.itemData.ids.forEach((itemId, index) => {
//                 let itemCount = this.itemData.counts[index];
//                 if (isDouble) {
//                     itemCount *= 2;
//                 }
//                 this.awardItem(itemId, itemCount);
//             });

//             if (PlayerDataMgr.GetGuideIndexByTaskName(GuideName.仓库升级) === UpEquipLevelGuideIndex.给固定奖励1) {
//                 PlayerDataMgr.SetGuideIndex(GuideName.仓库升级, UpEquipLevelGuideIndex.引导点击仓库水果2);
//             }
//         }
//     }

//     private awardItem(itemId: number, itemCount: number): void {
//         switch (itemId) {
//             case HallGlobalVariable.goldId:
//                 PlayerDataMgr.AddGold(itemCount);
//                 break;
//             case 12345:
//                 const currentState = GameDataMgr.getNowLevelBoshuState(this.nowlevel, 1);
//                 GameDataMgr.updateTiaoZhanFen(1, 100 * currentState);
//                 break;
//             default:
//                 PlayerDataMgr.AddEquipFragments(itemId, itemCount);
//         }
//     }

//     /**
//      * 返回主页
//      * 建议方法名：backToHome
//      */
//     private onBackHome(): void {
//         this.nowdata.back(2);
//         this.onCloseView();
//     }

//     /**
//      * 处理返回事件
//      * 建议方法名：handleBackEvent
//      */
//     private onBack(): void {
//         this.nowdata.back(2);
//         this.onCloseView();
//     }

//     /**
//      * 关闭界面
//      * 建议方法名：closeView
//      */
//     private onCloseView(): void {
//         this._close();
//         EventMgrInstance.dispatchEvent(EVENT_TYPE.Game_Value_Fei);
//     }

//     /**
//      * AI检查
//      * 建议方法名：performAICheck
//      */
//     private AICheck(): void {
//         if (AIControl._instance.isOpen) {
//             this.scheduleOnce(() => {
//                 AIControl._instance.ShowClickBtn(this.auto_ui.btn_queding.node, () => {
//                     this.GetReward(false);
//                     this.onBackHome();
//                 });
//             }, 1);
//         }
//     }
// }


import AICtrl from "./AIControl";
import { AudioMgr } from "./AudioManager";
import { BundleNames } from "./BundleConfig";
import CommonUtils from "./CommonUtils";
import { GetItemsData } from "./Const_Hall";
import { EventMgrInstance } from "./EventManager";
import { EVENT_TYPE } from "./EvenType";
import { Excel } from "./Excel";
import { GameDataMgr } from "./GameDataManager";
import { GameGlobalVariable } from "./GameGlobalVariable";
import FruitDataManager from "./HallGlobalVariable";
import { LogMgr } from "./LogManager";
import { PlayerDataMgr } from './PlayerDataManager';
import UIGameOverUIBindings from "./UI_GameOver_UIBindings";
import ViewGameOverItem from "./UI_GameOverItem";
import UIViewBase from "./UIView";
// import TTAPI from "./TTAPI";
import { ADMgr } from "./ADManager";
import { GuideName, UpEquipLevelGuideIndex } from "./Const_Common";
import { FruitId } from "./Const_Game";

const { ccclass, property } = cc._decorator;

/** 
 * 游戏结束界面控制类
 * 建议类名：GameOverView
 */
@ccclass
export default class ViewGameOver extends UIViewBase {
    @property(UIGameOverUIBindings)
    public auto_ui: UIGameOverUIBindings = null;

    public nowdata: any = {};
    public nowlevel: number = 1;

    public itemData: GetItemsData = null;

    /**
     * 显示游戏结束界面
     * @param {any} endData 游戏结束的数据
     * 建议方法名：showGameOver
     */
    public _show(...args: any[]): void {
        const [endData] = args;
        this.nowdata = endData;
        this.nowlevel = GameGlobalVariable.nowlevel;
        this.auto_ui.btn_fenxiang.node.active = true;

        if (GameGlobalVariable.isSpecialLevel() === 1) {
            this.auto_ui.btn_fenxiang.node.active = false;
            this.nowlevel = GameGlobalVariable.teshulevel;
            PlayerDataMgr.subtractWuJinCount(1);
        }
        if (this.nowdata.type === 1) {
            this.updateFailUI();
        } else {
            this.updateSuccessUI();
        }

        if (GameGlobalVariable.isSpecialLevel() === 1) {
            this.initTiaoZhanAward();
        } else {
            this.initAward();
        }

        this.checkAI();
        GameDataMgr.updateCiTiaoData(this.nowlevel, null);
        CommonUtils.clearCoins();
    }

    private updateFailUI(): void {
        this.auto_ui.node_successtop.active = false;
        this.auto_ui.node_failtop.active = true;
        this.animateScaleNode(this.auto_ui.node_failtop);
        const highestBoshuState = GameDataMgr.getCurrentLevelWaveState(this.nowlevel, GameGlobalVariable.isSpecialLevel());
        this.auto_ui.txt_nowboshu.string = `最高进度:第${highestBoshuState}波`;
        AudioMgr.playSoundEffect("sound/失败", false, BundleNames.Game);
    }

    private updateSuccessUI(): void {
        AudioMgr.playSoundEffect("sound/胜利", false, BundleNames.Game);
        this.auto_ui.node_successtop.active = true;
        this.animateScaleNode(this.auto_ui.node_successtop);
        this.auto_ui.node_failtop.active = false;
    }

    /**
     * 缩放节点动画
     * @param node 要进行动画的节点
     * 建议方法名：animateScaleNode
     */
    private animateScaleNode(node: cc.Node): void {
        this.scheduleOnce(() => {
            node.scale = 0;
            cc.tween(node)
                .to(0.3, { scale: 1 }, { easing: "backOut" })
                .start();
        });
    }

    /**
     * 初始化挑战奖励
     * 建议方法名：initChallengeAward
     */
    private initTiaoZhanAward(): void {
        const multiplier = 100 * GameDataMgr.getCurrentLevelWaveState(this.nowlevel, 1);
        this.itemData = new GetItemsData();
        this.itemData.ids = [];
        this.itemData.counts = [];
        this.itemData.ids.push(12345);
        this.itemData.counts.push(multiplier);
        this.initAwardUi(this.itemData);
    }

    /**
     * 初始化奖励
     * 建议方法名：initLevelAward
     */
    private initAward(): void {
        const levelConfig = Excel.shuiguoguanqia(this.nowlevel);
        const levelAwards = levelConfig.levelaward;
        const boshuState = GameDataMgr.getCurrentLevelWaveState(this.nowlevel, 2);
        const firstAward = levelAwards[0][1];

        this.itemData = new GetItemsData();
        this.itemData.ids = [];
        this.itemData.counts = [];

        GameGlobalVariable.isFirstGuide = false;

        if (PlayerDataMgr.getGuideIndexByTaskName(GuideName.EquipLevelUp) === UpEquipLevelGuideIndex.GiveFixedReward1) {
            this.itemData.ids.push(FruitDataManager.goldId);
            this.itemData.counts.push(200);
            this.itemData.ids.push(FruitId.杨桃忍者);
            this.itemData.counts.push(4);
        } else {
            const calcAward = Math.floor(boshuState * (firstAward / levelConfig.levelboshuid.length));
            if (calcAward > 0) {
                this.itemData.ids.push(FruitDataManager.goldId);
                this.itemData.counts.push(calcAward);
            }
            GameGlobalVariable.addjinbi = calcAward;

            const calculatePieceCount = (threshold, amount) => boshuState < threshold ? 0 : Math.floor(((boshuState + 1 - threshold) / (levelConfig.levelboshuid.length + 1 - threshold)) * amount);

            const greenPiece = calculatePieceCount(levelConfig.awardboshuid[0], levelAwards[1][2]);
            LogMgr.debug("绿色碎片数量", greenPiece);

            const bluePiece = levelAwards[2] && calculatePieceCount(levelConfig.awardboshuid[1], levelAwards[2][2]);
            LogMgr.debug("蓝色碎片数量", bluePiece);

            const purplePiece = levelAwards[3] && calculatePieceCount(levelConfig.awardboshuid[2], levelAwards[3][2]);
            LogMgr.debug("紫碎片数量", purplePiece);

            FruitDataManager.getSuiPian([greenPiece, bluePiece, purplePiece]).forEach((count, idx) => {
                this.itemData.ids.push(idx);
                this.itemData.counts.push(count);
                PlayerDataMgr.addEquipFragments(idx, count);
            });
        }
        this.initAwardUi(this.itemData);
        const maxLevel = GameDataMgr.getCurrentMaxLevel();
        if (cc.sys.platform === cc.sys.BYTEDANCE_GAME) {
            // TTAPI.setImRankData(maxLevel);
        }
    }

    /**
     * 获取当前的节点列表
     * @param {any} awardData 奖励数据
     * @returns {cc.Node[]} 当前的节点列表
     * 建议方法名：getCurrentNodes
     */
    private getNodes(awardData): cc.Node[] {
        const itemCount = awardData.ids.length;
        let rowCount = 1;
        if (itemCount > 4) {
            const remainder = itemCount % 4;
            rowCount = (itemCount - remainder) / 4 + (remainder > 0 ? 1 : 0);
        }
        const children = this.auto_ui.scroll_nowscroll.content.children;
        const nodeArray = [];
        let itemIndex = 0;

        for (let i = 0; i < children.length; i++) {
            const row = children[i];
            if (i < rowCount) {
                row.active = true;
                row.children[0].children.forEach((child) => {
                    if (itemIndex < awardData.ids.length) {
                        child.scale = 0;
                        nodeArray.push(child);
                        itemIndex++;
                    } else {
                        child.active = false;
                    }
                });
            } else {
                row.active = false;
            }
        }
        return nodeArray;
    }

    /**
     * 初始化奖励UI
     * @param {any} awardData 奖励数据
     * 建议方法名：initAwardUserInterface
     */
    private initAwardUi(awardData): void {
        const nodes = this.getNodes(awardData);
        let currentIndex = 0;
        this.schedule(
            () => {
                const currentNode = nodes[currentIndex];
                const itemId = awardData.ids[currentIndex];
                const itemCount = awardData.counts[currentIndex];
                currentNode.getComponent(ViewGameOverItem).initUI(itemId, itemCount);
                cc.tween(currentNode)
                    .to(0.3, { scale: 1 }, { easing: "backOut" })
                    .start();
                currentIndex += 1;
            },
            0.1,
            nodes.length - 1
        );
    }

    /**
     * 点击事件监听器
     * @param {cc.Event.EventCustom} event 点击事件
     * 建议方法名：clickListener
     */
    protected _clickListener(event: cc.Button): void {
        const uiBindings = this.auto_ui;
        switch (event) {
            case uiBindings.btn_fenxiang:
                this.handleShareButtonClick();
                break;
            case uiBindings.btn_queding:
                this.getReward(false);
                this.onBackHome();
        }
    }

    private handleShareButtonClick(): void {
        if (cc.sys.isBrowser) {
            this.doubleRewards();
            this.auto_ui.btn_fenxiang.node.active = false;
        } else {
            // ADMgr.shareGame(()=>{
            //     this.doubleRewards();
            //     this.auto_ui.btn_fenxiang.node.active = false;
            // });
           
            CommonUtils.onShare((isShared) => {
                if (isShared) {
                    this.doubleRewards();
                    this.auto_ui.btn_fenxiang.node.active = false;
                }
            });
        }
    }

    private doubleRewards(): void {
        this.itemData.counts = this.itemData.counts.map(count => count * 2);
        this.initAwardUi(this.itemData);
    }

    /**
     * 获取奖励
     * @param {boolean} isDouble 是否双倍
     * 建议方法名：getReward
     */
    private getReward(isDouble: boolean): void {
        if (this.itemData) {
            this.itemData.ids.forEach((itemId, index) => {
                let itemCount = this.itemData.counts[index];
                if (isDouble) {
                    itemCount *= 2;
                }
                this.awardItem(itemId, itemCount);
            });

            if (PlayerDataMgr.getGuideIndexByTaskName(GuideName.EquipLevelUp) === UpEquipLevelGuideIndex.GiveFixedReward1) {
                PlayerDataMgr.setGuideIndex(GuideName.EquipLevelUp, UpEquipLevelGuideIndex.GuideClickWarehouseFruit2);
            }
        }
    }

    private awardItem(itemId: number, itemCount: number): void {
        switch (itemId) {
            case FruitDataManager.goldId:
                PlayerDataMgr.addGold(itemCount);
                break;
            case 12345:
                const currentState = GameDataMgr.getCurrentLevelWaveState(this.nowlevel, 1);
                GameDataMgr.updateChallengePoints(1, 100 * currentState);
                break;
            default:
                PlayerDataMgr.addEquipFragments(itemId, itemCount);
        }
    }

    /**
     * 返回主页
     * 建议方法名：backToHome
     */
    private onBackHome(): void {
        this.nowdata.back(2);
        this.onCloseView();
    }

    /**
     * 处理返回事件
     * 建议方法名：handleBackEvent
     */
    private onBack(): void {
        this.nowdata.back(2);
        this.onCloseView();
    }

    /**
     * 关闭界面
     * 建议方法名：closeView
     */
    private onCloseView(): void {
        this._close();
        EventMgrInstance.emitEvent(EVENT_TYPE.Game_Value_Fei);
    }

    /**
     * AI检查
     * 建议方法名：performAICheck
     */
    private checkAI(): void {
        if (AICtrl._instance.isOpen) {
            this.scheduleOnce(() => {
                AICtrl._instance.displayClickButton(this.auto_ui.btn_queding.node, () => {
                    this.getReward(false);
                    this.onBackHome();
                });
            }, 1);
        }
    }
}